package com.kpx.app.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.RatingBar;

import com.kpx.app.R;
import com.kpx.app.base.ActivityBase;
import com.kpx.app.bean.OrderBean;
import com.kpx.app.configs.Constants;
import com.kpx.app.http.HttpDataApi;
import com.kpx.app.http.HttpDataLoader;
import com.kpx.app.http.HttpDataReqUrl;
import com.kpx.app.http.ResObj;
import com.kpx.app.utils.MyHashMap;
import com.kpx.app.utils.UIUtils;
import com.kpx.app.utils.uiutils.ToastUtil;
import com.kpx.app.view.TitleView;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by congdy on 17/4/16.
 */

public class ActivityOrderPrise extends ActivityBase {
    @BindView(R.id.titleview)
    TitleView titleview;
    @BindView(R.id.ratingBar)
    RatingBar ratingBar;
    @BindView(R.id.et_content)
    EditText etContent;
    private OrderBean b;

    @Override
    public void initview(@Nullable Bundle savedInstanceState) {
        setContentView(R.layout.activity_order_prise);
        ButterKnife.bind(this);
        UIUtils.setNormalTitle(titleview,"评价");
        titleview.setRight("发布", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                toSend();
            }
        },R.color.white);
    }

    private void toSend() {
        //orderId,content(评价内容),score(评分)
        showLoadingDialog();
        MyHashMap map = new MyHashMap();
        map.put("orderId",b.getDmId()+"");
        map.put("content",etContent.getText().toString().trim());
        map.put("score",ratingBar.getRating()+"");
        new HttpDataLoader(new HttpDataApi.OnRequestCallback() {
            @Override
            public void onRequestSuccess(String url, ResObj result, boolean isFrmCache) {
                dissmissLoadingDialog();
                if (result.getCode() == 0) {
                    ToastUtil.getInstance().showToast(ActivityOrderPrise.this, "评价成功");
                    finish();
                } else {
                    ToastUtil.getInstance().showToast(ActivityOrderPrise.this, result.getMsg());
                }
            }

            @Override
            public void onRequestError(String url, int statusCode, String error) {
                dissmissLoadingDialog();
                ToastUtil.getInstance().showToast(ActivityOrderPrise.this, error);
            }

        }, null, null).POST(HttpDataReqUrl.URL_POST_ORDER_PRISE, true, map);
    }

    @Override
    public void initData() {
        b = (OrderBean) getIntent().getExtras().getSerializable(Constants.KEY_ORDER_BEAN);
    }

    @Override
    public void onReceiver(Context context, Intent intent) {

    }

}
